import configobj

def createConfig(path):
    '''
    createHgrcConfig should create a config file similar to the following:

    [ui]

    username = Commiters Full Name <commiters.email@server.com>
    verbose = True
    editor = nano
    ssh = ssh -C

    [auth]

    uc-deploy.prefix  = https://uc-deploy.googlecode.com/hg/
    uc-deploy.username = commiter.email@server.org
    uc-deploy.password = repo_password

    uc-web2py-fab-deploy.prefix  = https://uc-web2py-fab-deploy.googlecode.com/hg/  
    uc-web2py-fab-deploy.username = commiter.email@server.org
    uc-web2py-fab-deploy.password = repo_password

    defaults = state._AttributeDict(
        COMMIT_USER_FULL_NAME = 'Commiters Full Name',
        COMMIT_EMAIL          = 'commiters.email@server.com',
        REPOSITORY            = 'uc-deploy',
        REPOSITORY_URL        = "https://{{ REPOSITORY }}.googlecode.com/hg/",
        REPOSITORY_PASSWORD   = 'password',
    )
    defaults.update(env.conf)
    env.hgrc = defaults
    '''
    COMMIT_USER_FULL_NAME = 'Commiters Full Name',
    COMMIT_EMAIL          = 'commiters.email@server.com',
    REPOSITORY            = 'uc-deploy',
    REPOSITORY_URL        = "https://{{ REPOSITORY }}.googlecode.com/hg/",
    REPOSITORY_PASSWORD   = 'password',
    REPPOSITRY_PREFIX     = '.prefix',
    config = configobj.ConfigObj()
    config.filename = path
    # create ui section 
    config["ui"] = {}
    config["ui"]["username"] = "{{ COMMIT_USER_FULL_NAME }} <{{ COMMIT_EMAIL }}>"
    config["ui"]["verbose"] = ['True']
    config["ui"]["editor"] = ['nano']
    config["ui"]["ssh"] = ['ssh -C']
    # create auth section 
#    config["auth"] = {}
#    config["auth"] = ["{{ REPOSITORY_PREFIX }}"]   = [{{ REPOSITORY_URL }}]
#    config["auth"] = [{{ REPOSITORY }} + '.username'] = [{{ COMMIT_EMAIL }}]
#    config["auth"] = [{{ REPOSITORY }} + '.password'] = [{{ REPOSITORY_PASSWORD }}]
#    config.write()

createConfig('hgrc')